﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Globalization;

/// <summary>
/// Summary description for Balance
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class Balance : System.Web.Services.WebService
{

    public Balance()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public int naptien(int sotien, int userid, string password)
    {
        BalanceDAL _balanceDAL = new BalanceDAL();
        return _balanceDAL.naptien(userid, password, sotien);
    }

    [WebMethod]
    public int ruttien(int sotien, int userid, string password)
    {
        BalanceDAL _balanceDAL = new BalanceDAL();
        return _balanceDAL.ruttien(userid, password, sotien);
    }

    [WebMethod]
    public int chuyenkhoan(int senderid, string password, string receivername, int sotien)
    {
        BalanceDAL _balanceDAL = new BalanceDAL();
        return _balanceDAL.chuyenkhoan(senderid, password, receivername, sotien);
    }

    [WebMethod]
    public DataSet getBanks()
    {
        BalanceDAL _balanceDAL = new BalanceDAL();
        return _balanceDAL.bankList();
    }

    [WebMethod]
    public DataSet getBalanceInfo(int userid)
    {
        BalanceDAL _balanceDAL = new BalanceDAL();
        return _balanceDAL.balanceinfo(userid);
    }

    [WebMethod(MessageName = "Simple", Description = "simple Method")]
    public DataSet GetTransactionLogs(int userid)
    {
        DateTime fromDay = new DateTime(1754, 1, 1);
        DateTime toDay = DateTime.Now;
        string type = "";
        BalanceDAL _balanceDAL = new BalanceDAL();
        return _balanceDAL.transactionlogs(userid, fromDay, toDay, type);
    }

    [WebMethod(MessageName = "Full", Description = "full Method")]
    public DataSet GetTransactionLogs(int userid, string fromDay, string toDay, string type)
    {
        if (type == "All" || type == null)
        {
            type = "";
        }
        object _fromDay, _toDay;
        IFormatProvider culture = new CultureInfo("en-US", true);

        try
        {
            _fromDay = DateTime.Parse(fromDay, culture);
        }
        catch (Exception)
        {
            _fromDay = null;
        }

        try
        {
            _toDay = DateTime.Parse(toDay, culture);
        }
        catch (Exception)
        {
            _toDay = null;
        }

        BalanceDAL _balanceDAL = new BalanceDAL();
        return _balanceDAL.transactionlogs(userid, _fromDay, _toDay, type);
    }
}

